package org.example;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Base64;

@Controller
public class IndexController {

    private static final Base64.Decoder decoder = Base64.getDecoder();
    // private static final Base64.Encoder encoder = Base64.getEncoder();

    @RequireAuth
    @RequestMapping("/login")
    @ResponseBody
    public String login(HttpServletRequest req, HttpServletResponse res) {
        return "{code: 0, data: {username:\"test\"}}";
    }

    @RequireAuth
    @RequestMapping("/index")
    @ResponseBody
    public String index(HttpServletRequest req, HttpServletResponse res) {
        return "{code: 0, data: {xxx:\"xxx\"}}";
    }

    @RequestMapping("/noBasicAuth")
    @ResponseBody
    public String noBasicAuth(HttpServletRequest req, HttpServletResponse res) {
        return "noBasicAuth res";
    }
}
